﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            循环输入图片(@"D:\\manhua\\魔法禁书目录漫画", 2);
        }

        /// <summary>
        /// 漫画地址
        /// </summary>
        /// <param name="path">漫画地址</param>
        /// <param name="ID">漫画ID</param>
        public static void 循环输入图片(string path,int ID)
        {

            string str = $"select * from ComicsInfo where ComicsID={ID}";
            if (DBHlper.Select(str).Rows.Count == 0) 
            {
                Console.WriteLine("确认漫画ID再加入你个憨憨");
                return;
            }           

            DirectoryInfo root = new DirectoryInfo(path);
            DirectoryInfo[] dics = root.GetDirectories();
            List<int> list = new List<int>();

            foreach (var item in dics) 
            {

                string[] lsl = Directory.GetFileSystemEntries(path + "\\" + item);
                int number = lsl.Length;
                string sql = $"insert into ChapterInfo(ComicsID,ChapterUrl,ImgNumber,ChapterWord) values('{ID}','{path+"\\"+item}','{number}','{item}')";
                if (DBHlper.Insert(sql)) 
                {
                    Console.WriteLine("添加成功:"+item);
                }
            }
            Console.WriteLine("添加完毕");
        }
    }
}
